import { DataTypes } from 'sequelize';
import sequelize from '../config/db.js';
const Like = sequelize.define('Like', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
  },
  user_id: {
    type: DataTypes.STRING(100),
    allowNull: false,
    references: {
      model: 'users', // 关联 users 表
      key: 'id',
    },
  },
  target_id: {
    type: DataTypes.BIGINT,
    allowNull: false,
    references: {
      model: 'wp_blog_posts', // 关联 wp_blog_posts 表
      key: 'ID',
    },
  },

  target_type: {
    type: DataTypes.STRING(50),
    allowNull: false,
  },
  like_status: {
    type: DataTypes.STRING(20),
  }
}, {
  tableName: 'likes',
  timestamps: true,
  updatedAt: 'updated_at',
  createdAt: 'created_at',
  indexes: [
    {
      unique: true,
      fields: ['user_id', 'target_id', 'target_type'],
    },
  ],
});

export default Like;